Attempts to compress the data in `source[0 .. sourceLen-1]' into the
destination buffer, `dest[0 .. *destLen-1]'. If the destination buffer
is big enough, `*destLen' is set to the size of the compressed data,
and `BZ_OK' is returned. If the compressed data won't fit, `*destLen'
is unchanged, and `BZ_OUTBUFF_FULL' is returned.
Compression in this manner is a one-shot event, done with a single
call to this function. The resulting compressed data is a complete
`bzip2' format data stream. There is no mechanism for making
additional calls to provide extra input data. If you want that kind of
mechanism, use the low-level interface.
For the meaning of parameters `blockSize100k', `verbosity' and
`workFactor',
see `bzCompressInit'.
To guarantee that the compressed data will fit in its buffer,
allocate an output buffer of size 1% larger than the uncompressed data,
plus six hundred extra bytes.
`bzBuffToBuffDecompress' will not write data at or beyond
`dest[*destLen]', even in case of buffer overflow.
Possible return values:
`BZ_PARAM_ERROR'
if `dest' is `NULL' or `destLen' is `NULL'
or `blockSize100k < 1' or `blockSize100k > 9'
or `verbosity < 0' or `verbosity > 4'
or `workFactor < 0' or `workFactor > 250'
`BZ_MEM_ERROR'
if insufficient memory is available
`BZ_OUTBUFF_FULL'
if the size of the compressed data exceeds `*destLen'
`BZ_OK'
otherwise
`bzBuffToBuffDecompress'
------------------------
int bzBuffToBuffDecompress ( char* dest,
unsigned int* destLen,
char* source,
unsigned int sourceLen,
int small,
int verbosity );
Attempts to decompress the data in `source[0 .. sourceLen-1]' into
the destination buffer, `dest[0 .. *destLen-1]'. If the destination
buffer is big enough, `*destLen' is set to the size of the uncompressed
data, and `BZ_OK' is returned. If the compressed data won't fit,
`*destLen' is unchanged, and `BZ_OUTBUFF_FULL' is returned.
`source' is assumed to hold a complete `bzip2' format data stream.
`bzBuffToBuffDecompress' tries to decompress the entirety of the stream
into the output buffer.
For the meaning of parameters `small' and `verbosity', see
`bzDecompressInit'.
Because the compression ratio of the compressed data cannot be known
in advance, there is no easy way to guarantee that the output buffer
will be big enough. You may of course make arrangements in your code to
record the size of the uncompressed data, but such a mechanism is beyond
the scope of this library.
`bzBuffToBuffDecompress' will not write data at or beyond
`dest[*destLen]', even in case of buffer overflow.
Possible return values:
`BZ_PARAM_ERROR'
if `dest' is `NULL' or `destLen' is `NULL'
or `small != 0 && small != 1'
or `verbosity < 0' or `verbosity > 4'
`BZ_MEM_ERROR'
if insufficient memory is available
`BZ_OUTBUFF_FULL'
if the size of the compressed data exceeds `*destLen'
`BZ_DATA_ERROR'
if a data integrity error was detected in the compressed data
`BZ_DATA_ERROR_MAGIC'
if the compressed data doesn't begin with the right magic bytes
`BZ_UNEXPECTED_EOF'
if the compressed data ends unexpectedly
`BZ_OK'
otherwise
File: bzip2.info, Node: zlib compatibility functions, Next: Using the library in a stdio-free environment, Prev: Utility functions, Up: Programming with libbzip2
`zlib' compatibility functions
==============================
Yoshioka Tsuneo has contributed some functions to give better `zlib'
compatibility. These functions are `bzopen', `bzread', `bzwrite',
`bzflush', `bzclose', `bzerror' and `bzlibVersion'. These functions
are not (yet) officially part of the library. If they break, you get
to keep all the pieces. Nevertheless, I think they work ok.
Opens a `.bz2' file for reading or writing, using either its name or
a pre-existing file descriptor. Analogous to `fopen' and `fdopen'.
int bzread ( BZFILE* b, void* buf, int len );
int bzwrite ( BZFILE* b, void* buf, int len );
Reads/writes data from/to a previously opened `BZFILE'. Analogous
to `fread' and `fwrite'.
int bzflush ( BZFILE* b );
void bzclose ( BZFILE* b );
Flushes/closes a `BZFILE'. `bzflush' doesn't actually do anything.
Analogous to `fflush' and `fclose'.
const char * bzerror ( BZFILE *b, int *errnum )
Returns a string describing the more recent error status of `b', and
also sets `*errnum' to its numerical value.
File: bzip2.info, Node: Using the library in a stdio-free environment, Next: Making a Windows DLL, Prev: zlib compatibility functions, Up: Programming with libbzip2
Using the library in a `stdio'-free environment
===============================================
Getting rid of `stdio'
----------------------
In a deeply embedded application, you might want to use just the
memory-to-memory functions. You can do this conveniently by compiling
the library with preprocessor symbol `BZ_NO_STDIO' defined. Doing this
gives you a library containing only the following eight functions: